
#导入需要的库和函数
import numpy as np
from sklearn.datasets.samples_generator import make_classification
from sklearn.model_selection import train_test_split
import pandas as pd

#创建分类数据集，其样本数量为200
X,labels = make_classification(n_samples=200, n_features=2, n_redundant=0, n_informative=2,
                               random_state=1, n_clusters_per_class=2)
rng = np.random.RandomState(2)
X += 2*rng.uniform(size=X.shape)


print(X.shape)
print(labels.shape)

#切分数据集为训练和测试两部分，其中测试数据的比例为20%
X_train, X_test, y_train, y_test = train_test_split(X, labels, test_size=0.2)


#字典中的key值即为csv中列名
dataframe = pd.DataFrame({'x1':X_train[:,0], 'x2':X_train[:, 1] , 'y':y_train})

#将DataFrame存储为csv,index表示是否显示行名，default=True
dataframe.to_csv("d:\\train_data.csv",index=False, sep=',', float_format='%10f')

#字典中的key值即为csv中列名
dataframe = pd.DataFrame({'x1':X_test[:,0], 'x2':X_test[:, 1] , 'y':y_test})

#将DataFrame存储为csv,index表示是否显示行名，default=True
dataframe.to_csv("d:\\test_data.csv",index=False, sep=',', float_format='%10f')